<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" session="false" %>
<%@ include file="/WEB-INF/jspf/import.jspf" %>
<!doctype HTML>
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
        <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
        <title>${fn:escapeXml(subject.title)}</title>
        <meta name="keywords" content="" />
        <meta name="description" content="" />
        <meta name="author" content="WangCaixia_gz ZhongQingbiao_gz"/>
        <link rel="stylesheet" type="text/css" href="http://js.3conline.com/wap/pcauto/2015/club_brand/brand_topic_V2.css">

    </head>

    <body class="g-doc" id="Jlazy_img">
        <jsp:include page="/template/wap/common/counter.jspf">
            <jsp:param name="channel" value="8234" />
        </jsp:include>
        <!-- 公共头部 --> 
        <%@include file="../common/intf6007.html" %>
        <!-- 公共头部end -->
        <!-- 公共头部 S -->
        <nav class="g-hd" id="JtopLink">
            <a href="javascript:history.go(-1);" class="header-back"></a>
            <div class="header-title">
                <span class="header-title-nav">
                   ${fn:escapeXml(subject.title)}
                </span>
            </div>
            <!-- <a class="g-hd-btn g-hd-btn-edit" href="http://m.pcauto.com.cn/club/select/"></a> -->
        </nav>
        <!-- 公共头部 E -->
        <!-- 大背景图头部 E --> 
        	<div class="m-topic">
        <c:if test="${isSubjectOnwer== true}">
           	<a href="${WAPROOT}/topic/${subject.subjectId}/edit" class="u-aImg">
			<i class="arrow"></i>
        </c:if>
	    <c:if test="${isSubjectOnwer== false}">
           	<a href="javascript:;" class="u-aImg">
        </c:if>
			<img src="${empty subject.logo ? subject.defaultLogo : subject.logo}">
			<p class="u-aImg-tit">${fn:escapeXml(subject.title)}</p>
			<p class="u-aImg-sum"><i>阅读</i><em>${subject.pvCount}</em><i>讨论</i><em>${subject.replyCount}</em></p>
		</a>
		    <div onclick="javascript:location.href='${WAPROOT}/subject/subjectIntroduction.do?subjectId=${subject.subjectId}'" class="m-topic-sum">${subject.introduction}</div>
		<p class="pic-wrap">
		   <c:forEach items="${subjectPhotos}" var="subjectPhoto">
			  <img width="68" height="68" src="" #src="${subjectPhoto.url134x134}" data-meta="${subjectPhoto.url400x400}" />
		  </c:forEach>
		</p>
		
	</div>
        
        <div class="publish-box clf">
            <textarea name="" id="J-txt-publish" data-txt="${fn:escapeXml(subject.title)}">${fn:escapeXml(subject.title)}</textarea>
            <div class="pic-upload clf" id="J-picWrap" >
                <div class="picfile-wrap" id="J-picfileWrap">
                </div>
            </div>

            <div class="pub-tools" id="J-pub-tools" style="display:none">
                <div class="clf">
                    <span class="m-face-pic-btn clf" id="JfatieTfFaceBtn">
                        <i class="m-face-btn"></i>
                        <i class="m-pic-btn" id="J-pic-btn">
                            <input type="file" name="picfile0" id="uploadFirst" class="picfile" onchange="firstUpload(this)" accept="image/*">
                        </i>
                    </span>
                    <div class="cel-sub-btn clf">
                        <i class="cancel-btn">取消</i>
                        <i class="submit-btn" onclick="postSubject();" id="submitBtn">发布</i>
                    </div>
                </div>
                <div class="m-face-list"></div>
            </div>
        </div>
        <!-- 置顶开始 -->
          <div class="m-top-item" id="topList">
   
          </div>
    <a href="${WAPROOT}/hottopic" class="m-other-topic"><span></span>其他热门话题<i class="arrow"></i></a>
          
        <!--  置顶结束-->
        <div class="tab1" id="tab1">
            <div class="th swipe">
               
                <a class="">最新讨论</a>
                <a >最热讨论</a>
            </div>
            <div class="tb">
                <div class="con-wrap">
                    <div class="pub-wrap">
                        <div id="newList"></div>
                        <a href="javascript:;" id="J-loadmoreNew" class="loadmore"><i>点击加载更多</i></a>
                        <a href="javascript:;" id="noNewTopic" style="display:none" class="noTopic"><i>暂无讨论</i></a>
                    </div>
                    <div class="pub-wrap">
                        <div id="hotList"></div>
                        <a href="javascript:;" id="J-loadmoreHot" class="loadmore"><i>点击加载更多</i></a>
                        <a href="javascript:;" id="noHotTopic" style="display:none" class="noTopic"><i>暂无讨论</i></a>
                    </div>
                   
                </div>
            </div>
        </div>
         <!-- 公共底部 --> 
         <%@include file="../common/intf5987.html" %>
         <!-- 公共底部end --> 
        <script type="text/javascript" src="http://js.3conline.com/wap/pcauto/common/zepto1.1.6.min.js" ></script>
        <script src="http://js.3conline.com/wap/pcauto/2015/club_brand/js/fatie.js" type="text/javascript"></script>
        <script src="http://js.3conline.com/wap/common/swipe.extend-min.js" charset="utf-8"></script>
       <script src="http://js.3conline.com/wap/common/wap.lazy-min.js" type="text/javascript"></script>
        <script src="http://js.3conline.com/wap/pcauto/2015/club_brand/js/showBigPic.js"></script>
       <script>
		// 增加S
		$('.pub-item .m-handle').live('click',function(){
		    if(!$(this).hasClass('m-cancle')){
		        $('.pub-item .m-handle').removeClass('m-cancle');
		        $(this).addClass('m-cancle');
		    }
		})
		$('.pub-item .m-handle span').live('click',function(){
		    $(this).parent().removeClass('m-cancle');
		})
		// 增加E
		</script>
       
        <script type="text/javascript">
         var hotUrl = "${WAPROOT}/subject/listHotSubjectDyna.do?callback=?";
         var newUrl = "${WAPROOT}/subject/listNewSubjectDyna.do?callback=?";
         var topUrl = "${WAPROOT}/subject/listSubjectTopDyna.do";
         var praiseUrl="${WAPROOT}/dyna/doPraise.do";
         var postUrl = "${WAPROOT}/dyna/createCommentDyna.do";
         var isPraise = 1; //点过赞
         var noPraise = 0; //未点赞
         var hotPageNo = 1;
         var newPageNo = 1;
         var pageSize = 10;
         var isPosting = false; //是否正在提交
         var isLogin = ${isLogin}; //是否登录
         var isSwipe=0;
         var subjectId = "${subject.subjectId}";
         var dynaHtml = '<article class="pub-item" id="dynaInfoDiv-{dynaInfoId}">{topTitle}<div class="m-list-head"><a href="{userUrl}" title="{nickName}" class="hd-ph-wrap {vip}"><img class="user-hd-ph" src="{userFace}" alt=""></a><p class="user-name">{nickName}</p><p class="pub-type">发表了说说</p>{topBtn}</div><section class="content"><h3 class="">{title}</h3>{picHtml}</section><footer class="pub-foot"><span class="pub-time">{time}</span><div class="re-wrap"><a href="javascript:void(0)" onclick="doPraise(this);" class="like {praiseClass}" data-dynaInfoId={dynaInfoId} data-createDate={createDate} data-isPraise={isPraise}><i class="icon"></i><em>{praiseCount}</em></a><a href="{dynaInfoUrl}" class="reply"><i class="icon"></i><em>{replyCount}</em></a></div></footer></article>';
         var photoHtml = '<div class="pic-wrap">{picUrl}</div>';
         var smiliesUrlRoot = "http://www1.pcauto.com.cn/autobbs/2013/images/emot/";
         var smilies_array = [];
             smilies_array[0] = [];
             smilies_array[0][1] =[['em2001','[抠鼻]','em1017.gif','32','32','50'],
								    ['em2002','[鼓掌]','em1017.gif','32','32','50'],
								    ['em2003','[可爱]','em1017.gif','32','32','50'],
								    ['em2004','[偷笑]','em1017.gif','32','32','50'],
								    ['em2005','[晕]','em1017.gif','32','32','50'],
								    ['em2006','[调皮]','em1017.gif','32','32','50'],
								    ['em2007','[微笑]','em1017.gif','32','32','50'],
								    ['em2008','[流泪]','em1017.gif','32','32','50'],
								    ['em2009','[大哭]','em1017.gif','32','32','50'],
								    ['em2010','[憨笑]','em1017.gif','32','32','50'],
								    ['em2011','[闭嘴]','em1017.gif','32','32','50'],
								    ['em2012','[鄙视]','em1017.gif','32','32','50'],
								    ['em2013','[可怜]','em1017.gif','32','32','50'],
								    ['em2014','[无语]','em1017.gif','32','32','50'],
								    ['em2015','[发呆]','em1017.gif','32','32','50'],
								    ['em2016','[吐]','em1017.gif','32','32','50'],
								    ['em2017','[流汗]','em1017.gif','32','32','50'],
								    ['em2018','[翻白眼]','em1017.gif','32','32','50'],
								    ['em2019','[发怒]','em1017.gif','32','32','50'],
								    ['em2020','[尴尬]','em1017.gif','32','32','50'],
								    ['em2021','[亲亲]','em1017.gif','32','32','50'],
								    ['em2022','[擦汗]','em1017.gif','32','32','50'],
								    ['em2023','[快哭了]','em1017.gif','32','32','50'],
								    ['em2024','[色色]','em1017.gif','32','32','50'],
								    ['em2025','[阴险]','em1017.gif','32','32','50'],
								    ['em2026','[得意]','em1017.gif','32','32','50'],
								    ['em2027','[睡觉]','em1017.gif','32','32','50'],
								    ['em2028','[叹气]','em1017.gif','32','32','50'],
								    ['em2029','[嘘]','em1017.gif','32','32','50'],
								    ['em2030','[撇嘴]','em1017.gif','32','32','50'],
								    ['em2031','[傲慢]','em1017.gif','32','32','50'],
								    ['em2032','[饿]','em1017.gif','32','32','50'],
								    ['em2033','[困]','em1017.gif','32','32','50'],
								    ['em2034','[委屈]','em1017.gif','32','32','50'],
								    ['em2035','[骷髅]','em1017.gif','32','32','50'],
								    ['em2036','[敲头]','em1017.gif','32','32','50'],
								    ['em2037','[惊讶]','em1017.gif','32','32','50'],
								    ['em2038','[咒骂]','em1017.gif','32','32','50'],
								    ['em2039','[抓狂]','em1017.gif','32','32','50'],
								    ['em2040','[奋斗]','em1017.gif','32','32','50'],
								    ['em2041','[哼哼]','em1017.gif','32','32','50'],
								    ['em2042','[惊恐]','em1017.gif','32','32','50'],
								    ['em2043','[衰]','em1017.gif','32','32','50'],
								    ['em2044','[疑问]','em1017.gif','32','32','50'],
								    ['em2045','[拜拜]','em1017.gif','32','32','50'],
								    ['em2046','[强]','em1017.gif','32','32','50'],
								    ['em2047','[弱爆]','em1017.gif','32','32','50'],
								    ['em2048','[OK]','em1017.gif','32','32','50'],
								    ['em2049','[握手]','em1017.gif','32','32','50'],
								    ['em2050','[胜利]','em1017.gif','32','32','50'],
								    ['em2051','[大便]','em1017.gif','32','32','50'],
								    ['em2052','[心碎]','em1017.gif','32','32','50'],
								    ['em2053','[玫瑰]','em1017.gif','32','32','50'],
								    ['em2054','[小刀]','em1017.gif','32','32','50'],
								    ['em1001','[顶]','em1017.gif','32','32','50'],
								    ['em1002','[微笑]','em1017.gif','32','32','50'],
								    ['em1003','[晕]','em1017.gif','32','32','50'],
								    ['em1004','[汗]','em1017.gif','32','32','50'],
								    ['em1005','[抱抱]','em1017.gif','32','32','50'],
								    ['em1006','[狂笑]','em1017.gif','32','32','50'],
								    ['em1007','[害羞]','em1017.gif','32','32','50'],
								    ['em1008','[大哭]','em1017.gif','32','32','50'],
								    ['em1009','[吐]','em1017.gif','32','32','50'],
								    ['em1010','[问]','em1017.gif','32','32','50'],
								    ['em1011','[闭嘴]','em1017.gif','32','32','50'],
								    ['em1012','[鄙视]','em1017.gif','32','32','50'],
								    ['em1013','[胜利]','em1017.gif','32','32','50'],
								    ['em1014','[无语]','em1017.gif','32','32','50'],
								    ['em1015','[美女]','em1017.gif','32','32','50'],
								    ['em1016','[鬼脸]','em1017.gif','32','32','50'],
								    ['em1017','[白眼]','em1017.gif','32','32','50'],
								    ['em1018','[吻]','em1017.gif','32','32','50'],
								    ['em1019','[凶]','em1017.gif','32','32','50'],
								    ['em1020','[路过]','em1017.gif','32','32','50'],
								    ['em1021','[口水]','em1017.gif','32','32','50'],
								    ['em1022','[电话]','em1017.gif','32','32','50'],
								    ['em1023','[委屈]','em1017.gif','32','32','50'],
								    ['em1024','[握手]','em1017.gif','32','32','50'],
								    ['em1025','[已阅]','em1017.gif','32','32','50'],
								    ['em1026','[再见]','em1017.gif','32','32','50'],
								    ['em1027','[抓狂]','em1017.gif','32','32','50'],
								    ['em1028','[鼓掌]','em1017.gif','32','32','50'],
								    ['em1029','[无聊]','em1017.gif','32','32','50'],
								    ['em1030','[害怕]','em1017.gif','32','32','50'],
								    ['em1031','[嘘]','em1017.gif','32','32','50'],
								    ['em1032','[下台]','em1017.gif','32','32','50'],
								    ['em1033','[偷看]','em1017.gif','32','32','50'],
								    ['em1034','[加油]','em1017.gif','32','32','50'],
								    ['em1035','[可怜]','em1017.gif','32','32','50'],
								    ['em1036','[受伤]','em1017.gif','32','32','50'],
								    ['em1037','[吃惊]','em1017.gif','32','32','50'],
								    ['em1038','[帅气]','em1017.gif','32','32','50'],
								    ['em1039','[睡觉]','em1017.gif','32','32','50'],
								    ['em1040','[发火]','em1017.gif','32','32','50'],
								    ['em1041','[酷]','em1017.gif','32','32','50'],
								    ['em1042','[思考]','em1017.gif','32','32','50'],
								    ['em1043','[得意]','em1017.gif','32','32','50'],
								    ['em1044','[聪明]','em1017.gif','32','32','50'],
								    ['em1045','[贪钱]','em1017.gif','32','32','50'],
								    ['em1046','[痛苦]','em1017.gif','32','32','50'],
								    ['em1047','[敬礼]','em1017.gif','32','32','50'],
								    ['em1048','[牛气冲天]','em1017.gif','32','32','50'],
								    ['em1049','[抠鼻子]','em1017.gif','32','32','50'],
								    ['em1050','[膜拜]','em1017.gif','32','32','50'],
								    ['em1051','[潜水]','em1017.gif','32','32','50'],
								    ['em1052','[挨打]','em1017.gif','32','32','50'],
								    ['em1053','[骷髅]','em1017.gif','32','32','50'],
								    ['em1054','[抱拳]','em1017.gif','32','32','50']];
            function  transformToBBSFace(str){
                var oldStr = str;
                for(var i=0,len=smilies_array[0][1].length; i<len; i++) {
                    var p = new RegExp(smilies_array[0][1][i][1].replace('[', '\\[').replace(']', '\\]'), 'gm');
                    str = str.replace(p, '['+smilies_array[0][1][i][0]+']');
                }
                return str;
            }
            function loadHotList(pageNo,pageSize,callback){
                setLoadingClass($('#J-loadmoreHot').find('i'));
                $.getJSON(hotUrl,{pageNo:pageNo,pageSize:pageSize,subjectId:subjectId},function(data){
                    if( data.code == 0 ){
                        var result = data.data;
                        if(result){
                            //获取讨论HTML模版
                            var html = templateHtml(result);
                            $("#hotList").append(html);
                            if(data.pageCount <= hotPageNo){
                            	 $("#J-loadmoreHot").hide();
                            }
                            if(!data.pageCount){
                                $("#J-loadmoreHot").hide();
                                $("#noHotTopic").show();
                            }
                            if(callback){
                                callback();
                            }
                        }
                    }
                },"json");
            }
            function loadNewList(pageNo,pageSize,callback){
                setLoadingClass($('#J-loadmoreNew').find("i"));
                $.getJSON(newUrl,{pageNo:pageNo,pageSize:pageSize,subjectId:subjectId},function(data){
                    if( data.code == 0 ){
                        var result = data.data;
                        if(result){
                            //获取讨论HTML模版
                            var html = templateHtml(result);
                            $("#newList").append(html);
                            if(data.pageCount <= newPageNo){
                                $("#J-loadmoreNew").hide();
                            }
                            if(!data.pageCount){
                                $("#J-loadmoreNew").hide();
                                $("#noNewTopic").show();
                            }
                            if(callback){
                                callback();
                            }
                        }
                        if(isSwipe == 0){
                            swipeTabA(document.getElementById("tab1"));
                            isSwipe = 1;
                         }
                    }
                },"json");
            }
            
            function loadTopList(){
                $.getJSON(topUrl,{subjectId:subjectId},function(data){
                    if( data.code == 0 ){
                        var result = data.data;
                        if(result){
                            //获取讨论HTML模版
                            var html = templateHtml(result);
                            $("#topList").append(html);
                        }

                    }
                },"json");
            }
            
            function templateHtml(result){
                var len = result.length;
                var html = "";
                for( var i = 0 ;i<len; i++ ){
                    var subject = result[i];
                    var pic = subject.images;
                    var isTop = subject.isTop;
                    var dynaInfoId = subject.dynaInfoId;
                    var createBy = subject.createBy;
                    var type = subject.type;
                    var isSubjectOnwer = subject.isSubjectOnwer;
                    var pHtml="";
                    var topHtml="";
                    var topText = "";
                    if(pic){
                        for(var j = 0; j<pic.length; j++){
                            pHtml += '<img width='+pic[j].width+' height='+pic[j].height+' src="http://www1.pcauto.com.cn/images/holder.png" #src="'+pic[j].smaPic+'" data-meta="'+pic[j].bigPic+'" alt="">'
                        } 
                    }
                    if(isTop){
                    	if(isSubjectOnwer){
                    	  topText += '<a href="javascript:void(0)" class="m-handle"><i class="handle"></i><span data-dynaInfoId='+dynaInfoId+' data-createBy='+createBy+' type='+type+' onclick="setTop(this)">取消置顶</span></a>';
                    	}
                    	topHtml += '<div class="m-list-top"><a href="javascript:void(0);">置顶</a></div>';
                    }else{
                    	if(isSubjectOnwer){
                    	   topText += '<a href="javascript:void(0)" class="m-handle"><i class="handle"></i><span data-dynaInfoId='+dynaInfoId+' data-createBy='+createBy+' type='+type+' onclick="setTop(this)">置顶</span><span data-dynaInfoId='+dynaInfoId+' data-createBy='+createBy+' onclick="deleteSubject(this)">删除</span></a>';
                    	}
                    }
                    html += dynaHtml.replace(/{dynaInfoId}/ig,dynaInfoId).replace(/{topTitle}/ig,topHtml).replace(/{nickName}/ig,subject.createName).replace(/{topBtn}/ig,topText).replace(/{title}/ig,subject.content).replace(/{userFace}/ig,subject.faceUrl).replace(/{picHtml}/ig,photoHtml.replace(/{picUrl}/ig,pHtml)).replace(/{time}/ig,subject.niceTime).replace(/{praiseClass}/ig,subject.isPraise>0?"i-like":"i-unlike").replace(/{praiseCount}/ig,subject.praiseCount>0?subject.praiseCount:"赞").replace(/{userUrl}/ig,"${UCWAPROOT}/"+subject.createBy).replace(/{dynaInfoId}/ig,subject.dynaInfoId).replace(/{createDate}/ig,subject.time).replace(/{isPraise}/ig,subject.isPraise?isPraise:noPraise).replace(/{replyCount}/ig,subject.postCount>0?subject.postCount:"回复").replace(/{dynaInfoUrl}/ig,"${UCWAPROOT}/"+subject.createBy+"/dt/"+subject.dynaInfoId).replace(/{vip}/ig,subject.isVip?"hd-ph-v":"hd-ph");
                }
                return html;
            }
            function setLoadingClass(ele){
                // load动画
                ele.attr('data-txt',ele.html());
                ele.html('');
                ele.addClass('loading');
                // 先写为auto
                $('.con-wrap').css('height','auto');
            }
            function loadHotCallback(){
                var parent = $('#J-loadmoreHot');
                var ele = parent.find('i');
                removeLoadingClass(ele,parent);
                lazyfun();
            }
            function loadNewCallback(){
                var parent = $('#J-loadmoreNew');
                var ele = parent.find('i');
                removeLoadingClass(ele,parent);
                lazyfun();
            }
            function removeLoadingClass(ele,parent){
                 // 去除load动画
                    ele.html(ele.attr('data-txt'));
                    ele.removeClass('loading');
                    var curHeight = $(parent).parent().height();
                    $('.con-wrap').height(curHeight);
            }
            function doPraise(e){
                if(!isLogin){
                    location.href="${UCWAPROOT}/passport/login.jsp?return="+location.href;
                    return;
                }
                var dynaInfoId = $(e).attr("data-dynaInfoId");
                var createDate = $(e).attr("data-createDate");
                var praise = $(e).attr("data-isPraise");
                if(dynaInfoId==null || createDate==null || isPraise == null){
                    return false;
                }
                var submitPraise = isPraise;
                if(praise == isPraise){
                    submitPraise = noPraise
                }
                if(!($(e).attr("isSending")=="true")){
                    $(e).attr("isSending",true);
                    $.post(praiseUrl,{dynaInfoId:dynaInfoId,createDate:createDate,isPraise:submitPraise},function(data){
                        var em = $(e).find("em");
                        var count = em.html();
                        if(submitPraise == isPraise){
                            $(e).removeClass("i-unlike");
                            $(e).addClass('i-like like-clicked');
                            $(e).attr("data-isPraise",isPraise);
                            if(count == "赞"){
                                em.html(1);
                            }else{
                                em.html(parseInt(count)+1);
                            }
                        }else if(submitPraise == noPraise){
                            $(e).attr("data-isPraise",noPraise);
                             $(e).removeClass("i-like");
                             $(e).addClass("i-unlike  like-clicked");
                            if(count <= 1){
                                em.html("赞");
                            }else{
                                em.html(parseInt(count)-1);
                            }
                        }
                        $(e).attr("isSending",false);
                    },"json");
                }
                
            }
            function setTop(obj){
        		$.post("${WAPROOT}/subject/setTop.do", {
                    subjectId:"${subject.subjectId}",
                    dynaInfoId:$(obj).attr("data-dynaInfoId"),
                    type: $(obj).attr("type"),
                    createBy:$(obj).attr("data-createBy")
                }, function(rs){
                    if(rs.code==0){
                        showTips(rs.message);
                    	window.location.reload(true);
                    }else{
                    	showTips(rs.message);
                    }
                }, "json");
        	}

        	function deleteSubject(obj){
        		var dynaInfoId = $(obj).attr("data-dynaInfoId");
        		$.post("${WAPROOT}/subject/deleteSubjectDyna.do", {
                    subjectId:"${subject.subjectId}",
                    dynaInfoId:dynaInfoId,
                    createBy:$(obj).attr("data-createBy")
                }, function(rs){
                    if(rs.code==0){
                    	showTips(rs.message);
                    	window.location.reload(true);
                    }else{
                    	showTips(rs.message);
                    }
                }, "json");
        	} 
            function setDisabledBtn(flg){
                if(flg){
                    $("#submitBtn").removeClass("submit-btn");
                    $("#submitBtn").addClass("cancel-btn");  
                }else{
                    $("#submitBtn").removeClass("cancel-btn");
                    $("#submitBtn").addClass("submit-btn");  
                }
            }
            function postSubject(){
                if(isPosting || isUploading()){
                    return;
                }
                var content = transformToBBSFace($("#J-txt-publish").val());
                if(content == null){
                    showTips("内容不能为空");
                    return;
                }
                var imagesjson = getImgJson();
                isPosting = true;
                setDisabledBtn(true);
                $.ajax({
                    url:postUrl,
                    type:"post",
                    data:{
                        needToViewUrl: 1,
                        content:content,
                        images:imagesjson,
                        fromType:1
                    },
                    dataType:"json",
                    success:function(data){
                        if(data.code == 0){
                            location.reload();
                        }else{
                            showTips(data.message);
                        }
                        isPosting = false;
                        setDisabledBtn(false);
                    },
                    error:function(){
                    showTips("网络错误");
                        isPosting = false;
                        setDisabledBtn(false);
                    }
                });
            }
            function addSubjectPV(){
                $.post("${WAPROOT}/subject/addPV.do", {
                    subjectId:"${subject.subjectId}"
                }, function(rs){
                    if(rs.code==0){
                    }
                }, "json");
            }
            function getImgJson(){
                var imagesjson = "[";
                for(var i = 0; i < imgData.length; i++){
                    imagesjson+= "{\"url\":\""+imgData[i].url+"\",\"seq\":"+(i+1)+",width:"+imgData[i].width+",height:"+imgData[i].height+"}";
                } 
                imagesjson +="]";
                return imagesjson;
            }
            loadHotList(hotPageNo,pageSize,loadHotCallback);
            loadNewList(newPageNo,pageSize,loadNewCallback);
            loadTopList();
            addSubjectPV();
            showBigPic('.pic-wrap img','.pic-wrap');
        </script>
        <script class="defer" src="http://js.3conline.com/wap/pcauto/2013/bbs/bbs_core.js" type="text/javascript" charset="utf-8"></script>
        <script type="text/javascript">
            // 修复active
            document.addEventListener("touchstart", function(){}, true);
            //切换tab
            function swipeTabA(ele) {
                // var wrap = ele.querySelector("div.tb"),
                var wrap = ele.querySelector("div.tb"),
                nav = ele.querySelector(".swipe");
                swipe(wrap, {
                    speed: 300,
                    nav: nav,
                    callback: function(index, elem) {
                        elem.parentNode.style.height = (elem.clientHeight||elem.offsetHeight) + "px";
                    }
                });
            }
            // 按需加载
           function lazyfun(){
            var xx = Lazy.create({
                lazyId: "Jlazy_img",
                trueSrc: '#src',
                offset: 300, //灵敏度。如设置为100，表示滚动在距离目标位置100px执行，默认为半屏高度
                delay: 100, //该毫秒时间内触发则延时100毫秒再加载
                delay_tot: 1000 //滚动过程中多长时间后强行触发一次，默认值是 1000，单位毫秒
            });
             Lazy.init(xx);
            }
           
            $('#J-loadmoreHot').click(function(event){
                var ele = $(this).find('i');
                // 先判断是不是在加载状态,若是初次点击 则给予loading动画，并在此处处理ajax，屏蔽掉多次点击
                // 加载成功后去掉class loading
                if(!ele.hasClass('loading')){
                    loadHotList(++hotPageNo,pageSize,loadHotCallback);
                    removeLoadingClass(ele,$(this));
                }
            });
            $('#J-loadmoreNew').click(function(event){
                var ele = $(this).find('i');
                // 先判断是不是在加载状态,若是初次点击 则给予loading动画，并在此处处理ajax，屏蔽掉多次点击
                // 加载成功后去掉class loading
                if(!ele.hasClass('loading')){
                    loadNewList(++newPageNo,pageSize,loadNewCallback);
                }
            });
                $('#tab1').on('tap', '.like', function(event) {
                    doPraise(event);
                var mylike = $(this);
                setTimeout(function(){
                    mylike.removeClass('like-clicked');
                },400);
            });
            var publish = $("#J-txt-publish");
            publish.bind('focus', function(event) {
                if(!isLogin){
                    location.href="${UCWAPROOT}/passport/login.jsp?return="+location.href;
                    return;
                }
                $(this).css('height', '120px');
                if(imgData.length>0){
                    $('#J-picWrap').show();;
                }
                $('#J-pub-tools').show();
            });
            $(".cancel-btn").click(function(event) {
                var txt = publish.attr('data-txt');
                publish.val(txt);
                $('#J-pub-tools').hide();
                $('#J-picWrap').hide();
                var height = publish.attr("data-defaultHeight");
                publish.css("height",height);
            });
            var picWrap = document.getElementById('J-picWrap');
            var picfileWrap = document.getElementById("J-picfileWrap");
            var idNum = 0 ;
            var imgData=[];
            $(picWrap).on("click",".item",function(){
                imgData.splice($('#J-picWrap .item',picWrap).index(this), 1);
                picWrap.removeChild(this);
                if(!isUploading()){
                    setDisabledBtn(false);
                }
            });
            UPC.init({
                localProxy: '/favicon.ico',
                upcPath: "${UPCROOT}",
                command: [53003, 53004, 53016, 53017,53018,53019,53020],
                application: "autoclub"
            });
            function insertWrap(id){
                $(picfileWrap).before('<div class="item" id="imgDiv'+id+'"></div>');
            }
            function createInput() {
                idNum++;
                var inputEle = document.createElement("input");
                inputEle.setAttribute("onchange", "changeEvent(this)");
                inputEle.className = 'picfile';
                inputEle.type = 'file';
                inputEle.accept = 'image/*'; //只限定图片
                inputEle.id = "picfile" + idNum;
                inputEle.name = "picfile" + idNum;
                picfileWrap.appendChild(inputEle);
            }
            function firstUpload(obj){
                if(!obj){
                    return;
                }
                var f = $("#J-pic-btn");
                $('#J-picWrap').show();
                changeEvent(obj);
                f.click(function(){
                    $('#J-picWrap').toggle();
                });
            }
            function changeEvent(obj){
                if(!obj){
                    return;
                }
                if($("#J-picWrap .item").length==9){
                    showTips("最多只能上传9张");
                    return;
                }
                obj.style.display = "none";
                createInput();
                insertWrap(obj.id);
                doUpload(obj.id);
            }
            function doUpload(fileId){
                setDisabledBtn(true);
                UPC.post({
                    url: "/upload_quick.jsp",
                    data: {
                        rotate: 0,
                        keepSrc: 'true',
                        readExif: 'yes'
                    },
                    file: [fileId],
                    complete: function (json) {
                        if (json.retCode == 0) {
                            if(!picWrap.querySelector("#imgDiv"+fileId)){//上传一半取消
                                return;
                            }
                            var index = 0;
                            for(var i = 0;i<json.files.length;i++){
                                if(json.files[i].url.indexOf("1024x1024")!=-1){
                                    index=i;
                                }
                            }
                            var obj = new Object();
                            obj.url = json.files[index].url;
                            obj.width = json.files[index].width;
                            obj.height = json.files[index].height;
                            imgData.push(obj); 
                            picWrap.querySelector("#imgDiv"+fileId).innerHTML = '<img src="' + json.files[0].url + '" />'; //传图成功插入图片
                            
                        } else {
                            picWrap.removeChild(picWrap.querySelector("#imgDiv"+fileId));
                            showTips("上传失败");
                        }
                        if(!isUploading()){
                            setDisabledBtn(false);
                        }
                    }
                });
            }
            //是否正在上传中
            function isUploading(){
                var uploadSize = $("#J-picWrap .item").length;
                var dataSize = imgData.length;
                if(uploadSize != dataSize){
                    return true;
                }
                return false;
            }
            /*各种提示*/
            function showTips(msg){
                var tips = document.getElementById('Jtips');
                if(!tips) {
                    tips = document.createElement('div');
                    tips.id = 'Jtips';
                    tips.className = 'm-tips';
                    document.body.appendChild(tips);
                }
                tips.innerHTML = msg;
                tips.style.display = 'block';
                var tips_width = tips.clientWidth/2;
                tips.style.marginLeft = '-'+tips_width+'px';
                tips.style.opacity = 1;    
                setTimeout(function(){
                    tips.style.webkitTransition = 'all 0.3s ease-in';
                    tips.style.opacity = 0;
                    tips.style.marginTop = '-80px';
                    setTimeout(function(){
                        tips.style.display = 'none';
                        tips.style.marginTop = '-40px';
                    }, 300);
                }, 2000);
            }
      (function(){
                var txt = document.getElementById('J-txt-publish');
                var textareaHeight = txt.scrollHeight + 2;
                txt.style.height = textareaHeight+'px';
                txt.setAttribute('data-defaultHeight',textareaHeight+'px');
                
                //阻止A标签冒泡
                $(".m-topic-sum a").on("click",function(e){
                     event.stopPropagation();
                })
            }());
        </script>
    </body>
</html>
